package plus.easydo.data.source.config;

import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import plus.easydo.data.source.core.DataSourceManagerService;
import plus.easydo.data.source.manager.controller.DataSourceManagerController;
import plus.easydo.data.source.manager.service.impl.DataSourceManagerServiceImpl;

/**
 * @author laoyu
 * @version 1.0
 */
@Configuration
public class DynamicDataSourceAutoConfiguration {

        @Bean
        public MapperScannerConfigurer mapperScannerConfigurer() {
                MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
                mapperScannerConfigurer.setBasePackage("plus.easydo.**.mapper");
                return mapperScannerConfigurer;
        }

        /**
         * 数据源管理业务层
         *
         * @return plus.easydo.jdbc.manager.service.DataSourceManagerService
         * @author laoyu
         */
        @Bean
        public DataSourceManagerService dataSourceManagerService(){
                return new DataSourceManagerServiceImpl();
        }

        @Bean
        @ConditionalOnBean(DataSourceManagerService.class)
        public DataSourceManagerController dataSourceManagerController(){
                return new DataSourceManagerController();
        }

}
